<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:insert="~{include :: header('课程专集列表')}" />
    <th:block th:insert="~{include :: bootstrap-table-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mb-2">
    <div class="toolbar" id="toolbar" role="group">
        <form id="formId" class="form-inline">
            <a class="btn btn-success mr-1" onclick="addAlbumItem()" shiro:hasPermission="course:album:item">
                <i class="fa fa-plus"></i> 添加
            </a>
            <select name="albumName" class="form-control mr-1">
                <option value="">所属专集</option>
                <option th:each="album : ${courseAlbum}" th:text="${album.name}" th:value="${album.name}"></option>
            </select>
            <a class="btn btn-primary btn-rounded mr-1" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
            <a class="btn btn-warning btn-rounded" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
        </form>
    </div>
    <table id="bootstrap-table" class="table-striped"></table>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: bootstrap-table-js}" />
<script th:inline="javascript">
    var isAvailableDatas = [[${@dict.getType('qdx_course_state')}]];
    var sellTypeDatas = [[${@dict.getType('qdx_course_type')}]];
    var prefix = "/course/album/item";
    $(function() {
        var options = {
            url: prefix + "/list",
            removeUrl: prefix + "/remove",
            modalName: "专集内容",
            showPageGo: true,
            onEditableSave: onEditableSave,
            columns: [
                {
                    field: 'id',
                    align: 'center',
                    title: 'ID'
                },
                {
                    field: 'courseName',
                    title: '课程名称'
                },
                {
                    field: 'sellType',
                    title: '类型' ,formatter: function(value, row, index) {
                        return $.table.selectDictLabel(sellTypeDatas, value);
                    }
                },
                {
                    field: 'albumName',
                    title: '所属专集'
                },
                {
                    field: 'isAvailable',
                    align: 'center',
                    title: '课程状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(isAvailableDatas, value);
                    }
                },
                {
                    field: 'orderNum',
                    align: 'center',
                    width:"200px",
                    title: '排序(点击可修改)',
                    editable : {
                        type : 'number',
                        title : '排序',
                        emptytext : "【排序】为空",
                        validate : function(value) {
                            if (value.length === 0) {
                                return '排序不能为空';
                            }
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function onEditableSave (field, row, oldValue, $el) {
        var data = {"id": row.id, "orderNum": row[field]};
        $.post(prefix + "/edit", data, function (josn) {
            if (josn.code === 0) {
                $.modal.msgSuccess('操作成功！')
                $.form.reset()
            }
        })
    }

    function addAlbumItem() {
        $.modal.openTab("添加课程专集", prefix + "/add");
    }
</script>
</body>
</html>